package com.summer.mall.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/product_images/**").addResourceLocations("classpath:/uploads/product_images/");
        registry.addResourceHandler("/user_images/**").addResourceLocations("classpath:/uploads/user_images/");
        registry.addResourceHandler("/uploads/**").addResourceLocations("classpath:/uploads/");
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/index.html");
        registry.addViewController("/admin").setViewName("forward:/admin/index.html");
        registry.addViewController("/admin/index").setViewName("forward:/admin/index.html");
        registry.addViewController("/admin/login").setViewName("forward:/admin/login.html");
        registry.addViewController("/cs/cslogin").setViewName("forward:/cs/login.html");
        registry.addViewController("/cs/chat").setViewName("forward:/cs/customService.html");
        registry.addViewController("/service").setViewName("forward:/cs/chat.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}
